/** Lachlan Hewson-Doherty (h201384171)
 *  Diploma of Digital and Interactive Games
 *  lachlan_doherty@live.com.au
 *  2013
 */

package cabbage.database.operations;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import cabbage.database.utilities.DatabaseConnection;



public class CollectedGameplayOps {
	
	
	private DatabaseConnection db;
	
	
	public int insertCollected ( int livecollectible_id, int player_id ) throws SQLException{
		
		
		
		db = new DatabaseConnection
						();
		
		Connection conn = db.getConnection
									();
		
		PreparedStatement ps = conn.prepareStatement
										("insert into collected (livecollectible_id, player_id) values (?,?)", 
									Statement.RETURN_GENERATED_KEYS);
		
		ps.setInt
				(1, livecollectible_id);
		
		ps.setInt
				(2, player_id);

		ps.execute
				();
		
		ResultSet rs = ps.getGeneratedKeys
									();
		
		if (rs != null && rs.next()) {
			
			return rs.getInt(1);
			
		}
		
		conn.close();
		
		return 0;
		
	}

	
	

}
